package ufrj.bioinfo.example;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;


public class Client {

	public static void main(String[] args1) throws AxisFault {
		
		// Esta é a URL do serviço que pode ser testada no browser
		// http://rodrigo-laptop.no-ip.info:8080/axis2/services/Calculo/fibo?n=10

		RPCServiceClient serviceClient = new RPCServiceClient();

		EndpointReference targetEPR = new EndpointReference("http://rodrigo-laptop.no-ip.info:8080/axis2/services/Calculo");

		serviceClient.getOptions().setTo(targetEPR);

		int N = 10;
		
		Object[] argumentosOperacao = new Object[] { Integer.valueOf(N) };

		// Definindo a operacao
		QName operacao = new QName("http://example.bioinfo.ufrj", "fibo");

		Class[] returnTypes = new Class[] { Long.class };

		Object[] response = serviceClient.invokeBlocking( operacao,
				argumentosOperacao, returnTypes);

		Long result = (Long) response[0];

		if (result == null) {
			System.out.println("Erro no processamento!");
			return;
		}
		
		// Displaying the result
		System.out.println("Valor de fibonacci : " + result);

	}
}